function Food (ele){
    //保存对象
    this.ele=ele
this.len = 20
    this.foodObj=null
    this.foodX = 0
    this.foodY = 0
}

Food.prototype.create=function(){
    //1.创建一个div
    //设置样式（w20，h20，颜色，定位）
    let divobj=document.createElement('div')
    divobj.style.width=this.len+'px'
    divobj.style.height=this.len+'px'
    divobj.style.background='pink'
    divobj.style.position='absolute'
    //追加到页面中
     this.ele.appendChild(divobj)

     this.foodObj = divobj

     //让食物移动
     this.move()
}
Food.prototype.move=function(){
let foodXMaxNum = this.ele.clientWidth / this.len - 1// 40-1   
let foodYMaxNum = this.ele.clientHeight / this.len - 1// 20-1
this.foodX = Math.floor(Math.random() * (foodXMaxNum-0+1)+0) * this.len
this.foodY = Math.floor(Math.random() * (foodYMaxNum-0+1)+0) * this.len 


console.log(this.foodX)
console.log(this.foodY)
this.foodObj.style.left = this.foodX + 'px'
this.foodObj.style.top = this.foodY + 'px'

}